/*
Copyright 2010,2011 Matt Van Der Westhuizen

This file is part of CGLL.

CGLL is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

CGLL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with CGLL.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.chaoticengine.cgll.input;

import java.lang.reflect.Field;
import org.newdawn.slick.Input;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Text;

/**
 *
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
@Root(name="mouse")
public class MouseInputDevice implements InputDevice {
    public static final int LMB = Input.MOUSE_LEFT_BUTTON;
    public static final int MMB = Input.MOUSE_MIDDLE_BUTTON;
    public static final int RMB = Input.MOUSE_RIGHT_BUTTON;
    public static final int WHEEL_UP = LMB + MMB + RMB + 1;
    public static final int WHEEL_DOWN = LMB + MMB + RMB + 2;
    public static final int X_AXIS_MINUS = WHEEL_DOWN + 1;
    public static final int X_AXIS_PLUS = WHEEL_DOWN + 2;
    public static final int Y_AXIS_MINUS = WHEEL_DOWN + 3;
    public static final int Y_AXIS_PLUS = WHEEL_DOWN + 4;

    protected String key = "";
    protected int keyCode = -1;

    public MouseInputDevice() {}

    @Text
    public String getKey() {
        return(key);
    }

    @Text
    public void setKey(String key) {
        this.key = key;

        Field f = null;
        try {
            f = MouseInputDevice.class.getDeclaredField(key);
        } catch (NoSuchFieldException nsfEx) {
            System.out.println("Error: Key not found '" + key + "'.");
        }

        if (f != null) {
            try {
                keyCode = f.getInt(MouseInputDevice.class);
            } catch (IllegalAccessException iaEx) {
                System.out.println("Error: Key not accessible '" + key + "'.");
            }
        }
    }

    public int getKeyCode() {
        return(keyCode);
    }
}
